<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ page import="com.conversationboard.model.*" %>
<%@ page import="com.conversationboard.view.*" %>
<%@ page import="com.conversationboard.config.*" %>

<%@ page import="java.security.*" %>

<%@page pageEncoding="UTF-8"%>
<%@page contentType="text/html;charset=UTF-8"%>

<% 
	Board board = (Board) request.getAttribute("board");
	com.conversationboard.model.Thread thread = (com.conversationboard.model.Thread) request.getAttribute("thread");
	User user = (User) request.getAttribute("user");
	boolean mobileDevice = (Boolean) request.getAttribute("mobiledevice");
	
	int bookmarkedMessageId = (Integer) request.getAttribute("bookmarkedmessageid");

	String noIndex = "";
	
	if (board.isNoIndex() || thread.isDeindexed()) {
		noIndex = "<meta name=\"ROBOTS\" content=\"NOINDEX, FOLLOW\"></meta>";	
	}
	
	Principal principal = request.getUserPrincipal();
	boolean loggedIn = (principal != null);

	int originalMessageCount = 0;
	String body = "";
        
    Boolean bbCodeError = (request.getAttribute("bbCodeError") != null)? (Boolean) request.getAttribute("bbCodeError"): false;
    String ignoreBbCodeErrors = request.getParameter("ignoreBbCodeErrors");
    String[] bbCodeErrorContainer = null;
    
    /* The notion here is that the user would rather fix up bbcode errors before adding xpost addendums. */
    if (bbCodeError) {
            body = (String) request.getAttribute("body");
            
            bbCodeErrorContainer = new String[3];
            bbCodeErrorContainer[0] = (String) request.getAttribute("bbCodeErrorExplanation");
            bbCodeErrorContainer[1] = (String) request.getAttribute("bbCodeErrorPreContext");
            bbCodeErrorContainer[2] = (String) request.getAttribute("bbCodeErrorPostContext");
    } else if (request.getAttribute("originalmessagecount")!=null) {
		originalMessageCount = (Integer) request.getAttribute("originalmessagecount");
		body = (String) request.getAttribute("body");
	}
        

	// Are we to display all messages?
	
	String action = (String) request.getParameter("action");
	boolean showAllMessages = false;
	
	boolean admin = user.isBoardAdmin(board.getBoardId());
	
	Bookmarks bookmarks = user.getBookmarks();
	
	if ((action!=null) && (action.equals("showall"))) {
		showAllMessages = true;
	}

	String servletName = "NewAnswerControllerServlet";

	if (!board.isRequireRegistration()) {
		servletName = "unregistered/NewAnswerControllerServlet";
	}
	
%>

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta http-equiv="Pragma" content="no-cache" />
		<meta http-equiv="expires" content="0" />
		
		<%= noIndex %>
		<title>
			<c:if test="${not thread.deleted}">
				${thread.title}
			</c:if>
		</title>
		<link rel="stylesheet" title="Conversation Board" type="text/css" href="${contextPath}/Stylesheets/<%=StyleSheets.getStyleSheetFileName(request.getCookies())%>"></link>
		<script src="${contextPath}/Javascript/bbCodeize.js" type="text/javascript"></script> 
		<script src="${contextPath}/Javascript/style.js" type="text/javascript"></script>
		<script src="${contextPath}/Javascript/ajax.js" type="text/javascript"></script>
	</head>

	<body>

		<%= MenuDisplay.display(board, false, principal) %>

		<% if (SiteMessage.getMessage() != null) { %>	
			<div class='sitemessage'><%= SiteMessage.getMessage() %></div>
		<% } %>
		<% if (BatchMessage.getMessage() != null) { %>	
			<div class='batchmessage'><%= BatchMessage.getMessage() %></div>
		<% } %>

		<c:if test="${user.yellowCarded}">
			<div class="yellowcard">You Have Been Yellow Carded By a Moderator: ${user.yellowCardReason}</div>
		</c:if>

		<%= BookmarksDisplay.display(bookmarks, false, thread.getBoardId(), thread.getThreadId()) %>

		<div class="headingblock">
			<c:if test="${not thread.deleted}">
				<h1>${thread.title}</h1>
			</c:if>
		</div>
			
		<c:if test="${user.admin and thread.deindexed}">
			<div class="batchmessage"><strong>This thread is deindexed</strong></div>
		</c:if>

	
		<div class="mainblock">		

			<div class='bookmarked'>Message Bookmarked</div>
			<div class='unbookmarked'>Bookmark Removed</div>
			
			<%= MessagesDisplay.display(request, thread, user.getLoginId(), showAllMessages, originalMessageCount, bookmarkedMessageId, bbCodeErrorContainer, mobileDevice) %>

			<br />

			<% if (thread.isLocked()) { %>
				<div class="formsection">
					<p style="text-align: center"><strong>This thread has been locked by an administrator</strong></p>
				</div>
			<% } %>

			<% if ((!(thread.isLocked() || thread.isDeleted())) && (board.isPostable(user) && (loggedIn || (!board.isRequireRegistration())))) { %>

				<form class="formsection" action="<%=Configuration.getInstance().getRoot()%>/<%= servletName %>" method="post">
			 	
					<h2>Add a Post</h2>

				 	<input name="boardId" value="<%=board.getBoardId()%>" type="hidden" />
				 	<input name="threadId" value="<%=thread.getThreadId()%>" type="hidden" />
				 	<input name="messageCount" value="<%=thread.getMessageCount()%>" type="hidden" />
				 	<input name="sKey" value="<%= request.getSession().getId()%>" type="hidden" />
				 	
					<% if (Configuration.getInstance().isSupportFileUploads()) { %>
						<input type="button" value="    Upload a File...    " onclick="window.open('<%=Configuration.getInstance().getRoot()%>/Pages/file-upload.jsp?boardid=<%=board.getBoardId()%>','','menubar=no,toolbar=no,status=no,height=400,width=800');"></input>
						<% if (Configuration.getInstance().isOnlySupportImageUploads()) { %> (Only Images Supported)<% } %>
						<a class="menulink" href="<%=Configuration.getInstance().getRoot()%>/Pages/view-uploaded-files.jsp?offset=0&number=20">View My Uploaded Files...</a>
						<br /><br />
					<% } %>
	
					<div id='warning' style='display:none' class='notworksafe'><strong>Remember that you can't use HTML tags - look below for formatting help!</strong></div>
				 	<textarea class="textbox" name="text" id="postinput" rows=10 cols=800><%= body %></textarea>
				 	<br />
	
				 	<% if (user.isBoardAdmin(board.getBoardId())) { %>
					 	<label for="adminId"><strong>Post as Anonymous Admin:</strong></label>
					 	<input name="adminId" class="smalltextbox" value="" size=50 /><br /><br />
				 	<% } %>
				 	
					<% if (!board.isRequireRegistration() && (!admin)) { %>
					 	<label for="Display Name"><strong>Name</strong></label><br />
					 	<input name="displayname" class="smalltextbox" size=50 /><br /><br />
					<% } %>

					<% if (board.isRequireRegistration()) { %>
						<strong>Display Name: ${user.fullDisplayName}</strong><br /><br />					
					<% } %>
		
				 	<input type="submit" value="      Submit Post      " />
					<input type="button" value="Convert Simple HTML to BBcode" onclick="bbCodeFix('postinput')" />	
	                                
	                <% if (bbCodeError || ignoreBbCodeErrors != null) { %>
	                <input type="checkbox" name="ignoreBbCodeErrors"<%if (ignoreBbCodeErrors != null && ignoreBbCodeErrors.equals("on")) {%> checked="checked"<%}%> />Ignore BBcode Errors
	                <% } %>
					
				</form>

				
				<div class="formatting">			
					<h3>Formatting help</h3>
					
					<table>
						<tr>
							<td>For <strong>strong text</strong>, use:</td>
							<td><code>[b]<em class='inlinetext'>your text</em>[/b]</code></td>
						</tr>
						<tr>
							<td>For <em>emphasised text</em>, use:</td>
							<td><code>[i]<em class='inlinetext'>your text</em>[/i]</code></td>
						</tr>	
						<tr>
							<td>For <strike>strikethrough text</strike>, use:</td>
							<td><code>[s]<em class='inlinetext'>your text</em>[/s]</code></td>
						</tr>
		                <tr>
							<td>For <u>underlined text</u>, use:</td>
							<td><code>[u]<em class='inlinetext'>your text</em>[/u]</code></td>
						</tr>
						<tr>
							<td>For block quotes, use:</td>
							<td><code>[q]<em class='inlinetext'>your text</em>[/q]</code></td>
						</tr>
						<tr>
							<td>For literal, non-proportional text, use:</td>
							<td><code>[code]<em class='inlinetext'>your text</em>[/code]</code></td>
						</tr>
						<tr>
							<td>For images, use:</td>
							<td><code>[img]<em class='inlinetext'>http://www.website.com/yourimage.jpeg</em>[/img]</code></td>
						</tr>
						<tr>
							<td>For hyperlinks, use:</td>
							<td><code>[url=<em class='inlinetext'>http://www.mywebsite.com/mylink.html</em>]<em class='inlinetext'>My Link Title</em>[/url]</code> or<br />
		                                        <code>[url]<em class='inlinetext'>http://www.mywebsite.com/mylink.html</em>[/url]</code></td>
						</tr>
						<tr>
							<td>For YouTube embedded videos:</td>
							<td>Simply paste in the URL of the YouTube web page containing the video you wish to embed</td>
						</tr>
						<tr>
							<td>For bulleted lists:</td>
							<td>Place a -* at the start of each bullet point. The bulleted list will continue until you start a line without a -*</td>
						</tr>
					</table>
				</div>
					
				<div class="formattingLink">
					<p><a name="fh" href="#fh" onClick="setStyleByClass('div','formatting','display', 'inline'); setStyleByClass('div','formattingLink','display', 'none');">Show Formatting Help</a></p>
				</div>					
			
			</div>
	
			<%= MenuDisplay.display(board, false, principal) %>
			
			<p style="clear: left"></p>

		<% } %>

		<% if ((!loggedIn && board.isRequireRegistration())) { %>
			<div class="formsection"><strong>You must be logged in to post. Please either <a href="<%=Configuration.getInstance().getRoot()%>/LoginControllerServlet">login here</a>, or if you are not registered, you may <a href="Pages/register.jsp">register here</a>.</strong></div>
		<% } %>


		<!--<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>-->
		<!--<script type="text/javascript">_uacct = "UA-1148679-1";urchinTracker();</script>--> 
		
	</body>
	
</html>
